<template>
  <div class="nav-con">
    <!-- fullPath -->
    <el-menu
      :default-active="$route.fullPath"
      class="el-menu-vertical-demo"
      background-color="#0d2439"
      text-color="#fff"
      active-text-color="#ffd04b"
      :router="true"
      :collapse="sidebar"
    >
      <el-submenu
        :index="item.path"
        v-for="item in routes"
        :key="item.path"
        v-show="item.meta.type == type || type == 1"
      >
        <template slot="title">
          <i class="iconfont" :class="item.meta.icon"></i>
          <span>{{ item.meta.title }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            v-for="i in item.children"
            :index="item.path + '/' + i.path"
            :key="item.path + '/' + i.path"
            >{{ i.meta.title }}</el-menu-item
          >
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "MyNav",
  data() {
    return {
      routes: [],
    };
  },
  computed: {
    ...mapGetters(["sidebar", "type"]),
  },
  mounted() {
    console.log(this.$route);
    let routes = [];
    this.$router.options.routes.forEach((item) => {
      if (item.meta) {
        routes.push(item);
      }
    });
    this.routes = routes;
  },
};
</script>

<style lang="scss" scoped>
.nav-con {
  overflow: hidden;
  // width: 165px;
}
.el-menu {
  border-right: none;
}
.iconfont {
  margin-left: 5px;
  margin-right: 8px;
  font-weight: bold;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 165px;
  min-height: 400px;
}
</style>